<!--
 * @Author: 小花
 * @Date: 2022-03-27 18:19:26
 * @LastEditors: 小花
 * @LastEditTime: 2022-04-25 17:12:18
 * @Description: 
-->
<template>
  <div class='recordDetails_container'>
    <el-descriptions title="订单详情" :column="3" size="small" border>
      <template slot="extra">
      </template>
      <el-descriptions-item>
        <template #label>
          <i class="el-icon-s-order"></i>
          订单号
        </template>
        {{data.orderId}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="el-icon-user-solid"></i>
          用户名
        </template>
        {{data.userEntity.nickname}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-glass"></i>
          报修类型
        </template>
        {{data.repairTypeEntity.typeValue}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-map-marker"></i>
          报修地址
        </template>
        {{data.repairAddress}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="el-icon-question"></i>
          报修问题
        </template>
        {{data.repairContent}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-mobile fa-lg"></i>
          联系电话
        </template>
        {{data.repairPhone}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-calendar"></i>
          报修时间
        </template>
        {{data.repairDate}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-spinner"></i>
          报修状态
        </template>
        <el-tag :type="repairStatusStyle(data.statusCode)" effect="light" disable-transitions>
          {{data.repairStatusEntity.statusValue}}
        </el-tag>
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-calendar"></i>
          完成时间
        </template>
        {{data.repairComplateDate}}
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-user-md"></i>
          维修员
        </template>
        {{data.workerEntity.workerName }}({{data.workerEntity.nickname}})
      </el-descriptions-item>
      <el-descriptions-item>
        <template #label>
          <i class="fa fa-file-image-o"></i>
          图片资料
        </template>
        <el-image style="width: 30px; height: 30px; margin: 5px;" v-for="url in data.imgUrl"
          :key="url" :src="url" fit="fill" :preview-src-list="data.imgUrl"></el-image>
      </el-descriptions-item>
    </el-descriptions>
    <el-steps :active="steps.currentStep" align-center style="margin-top: 1rem;">
      <el-step v-for="(item, idx) in steps.step" :key="idx" :title="item.title"
        :status="item.status" :description="item.description"></el-step>
    </el-steps>
    <component :is="currentView"></component>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';
import { repairStatusStyle } from '@/js/public.js'
import { useMainStore } from '@/js/store.js'

import contactConfirmation from '@/components/workerHome/repairRecord/recordDetails/steps/contactConfirmation';
import applyMaterial from '@/components/workerHome/repairRecord/recordDetails/steps/applyMaterial';
import chargeOn from '@/components/workerHome/repairRecord/recordDetails/steps/chargeOn';
import orderCompleted from '@/components/workerHome/repairRecord/recordDetails/steps/orderCompleted';

export default {
  // workerHome中设置keep-alive不缓存该组件
  name: 'record_details',
  //import引入的组件需要注入到对象中才能使用
  components: {
    contactConfirmation,
    applyMaterial,
    chargeOn,
    orderCompleted
  },
  data () {
    //这里存放数据
    return {
      store: useMainStore(),
      data: {},
      repairStatusStyle,
      steps: {
        currentStep: 0,
        step: {
          contactConfirmation: { title: "联系确认", description: "", status: "" },
          applyMaterial: { title: "申报材料", description: "", status: "" },
          chargeOn: { title: "收费开启", description: "", status: "" },
          orderCompleted: { title: "订单完结", description: "", status: "" }
        }
      },
      currentView: '',
    }
  },
  //监控data中的数据变化
  watch: {
    'steps.currentStep': {
      handler: function () {
        this.currentView = ['contactConfirmation', 'applyMaterial', 'chargeOn', 'orderCompleted'].at(this.steps.currentStep);
      },
      // 监听方法会在创建的时候  执行handler里的方法
      immediate: true
    },
    'store.recordDetails.step': {
      handler: 'handleUrlParams',
      deep: true
    }
  },
  //方法集合
  methods: {
    handleUrlParams (nowVal) {

      let recordDetails = this.store.recordDetails;

      if (Object.keys(recordDetails).length == 0) {
        this.$router.go(-1);
        return
      }

      this.data = recordDetails.data;

      this.steps = recordDetails.step;

      // 更新订单记录页面 步骤条缓存数据
      let steps = this.store.steps;
      for (let i = 0; i < steps.length; i++) {
        if (steps[i].orderId == this.steps.orderId) {
          this.store.steps[i] = this.steps;
          break;
        }
      }
    }
  },
  //生命周期 - 创建完成（可以访问当前this实例）
  created () {
    this.handleUrlParams();
  }
}
</script>
